﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Surface;
using Microsoft.Surface.Presentation;
using Microsoft.Surface.Presentation.Controls;
using System.Collections.ObjectModel;
using SurfaceCardsGameKit.Games.BasicGame;

namespace SurfaceCardsGameKit 
{
    /// <summary>
    /// Interaction logic for Mosaic.xaml
    /// </summary>
    public partial class Mosaic : SurfaceListBox
    {

        public Brush BackBackground
        {
            get { return (Brush)GetValue(BackBackgroundProperty); }
            set { SetValue(BackBackgroundProperty, value); }
        }
        public static readonly DependencyProperty BackBackgroundProperty =
            DependencyProperty.Register("BackBackground", typeof(Brush), typeof(Mosaic), new UIPropertyMetadata(null));

        public bool IsFront
        {
            get { return (bool)GetValue(IsFrontProperty); }
            set { SetValue(IsFrontProperty, value); }
        }
        public static readonly DependencyProperty IsFrontProperty =
            DependencyProperty.Register("IsFront", typeof(bool), typeof(Mosaic), new UIPropertyMetadata(false));
        
        public Mosaic()
        {
            InitializeComponent();
        }
    }

    public class ColorsConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BasicCardsColor color = (BasicCardsColor)value;

            if(color == BasicCardsColor.Club)
                return Application.Current.FindResource("SmallTrefle") as Brush;
            if (color == BasicCardsColor.Diamond)
                return Application.Current.FindResource("SmallCarro") as Brush;
            if (color == BasicCardsColor.Heart)
                return Application.Current.FindResource("SmallCoeur") as Brush;
            if (color == BasicCardsColor.Spade)
                return Application.Current.FindResource("SmallPique") as Brush;

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class ColorsConverter2 : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BasicCardsColor color = (BasicCardsColor)value;

            if (color == BasicCardsColor.Club)
                return "Black";
            if (color == BasicCardsColor.Diamond)
                return "Red";
            if (color == BasicCardsColor.Heart)
                return "Red";
            if (color == BasicCardsColor.Spade)
                return "Black";

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class NumbersConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            BasicCardsNumber number = (BasicCardsNumber)value;

            if (number == BasicCardsNumber.C2)
                return "2";
            if (number == BasicCardsNumber.C3)
                return "3";
            if (number == BasicCardsNumber.C4)
                return "4";
            if (number == BasicCardsNumber.C5)
                return "5";
            if (number == BasicCardsNumber.C6)
                return "6";
            if (number == BasicCardsNumber.C7)
                return "7";
            if (number == BasicCardsNumber.C8)
                return "8";
            if (number == BasicCardsNumber.C9)
                return "9";
            if (number == BasicCardsNumber.C10)
                return "10";
            if (number == BasicCardsNumber.Jack)
                return "V";
            if (number == BasicCardsNumber.Queen)
                return "D";
            if (number == BasicCardsNumber.King)
                return "R";
            if (number == BasicCardsNumber.Ace)
                return "1";

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

    public class WrapPanelWidthConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            double number = (double)value;
            return number - 20;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }

}
